package eu.jpereira.trainings.designpatterns.structural.decorator.channel.decorator;

import eu.jpereira.trainings.designpatterns.structural.decorator.channel.SocialChannel;

public class WordCensor extends SocialChannelDecorator {

	private String censored;
	
	public WordCensor(String censored) {
		this.censored = censored;
	}

	/**
	 * @param string
	 * @param channel
	 */
	//public WordCensor(String censored, SocialChannel channel) {
	//	this.censored = censored;
	//	this.delegate = channel;
	//}

	/*
	 * (non-Javadoc)
	 * 
	 * @see eu.jpereira.trainings.designpatterns.structural.decorator.channel.
	 * SocialChannel#deliverMessage(java.lang.String)
	 */
	@Override
	public void deliverMessage(String message) {
		StringBuilder builder = new StringBuilder();		
		String string = message.replace(censored, "*bleep*");
		builder.append(string);
		
		if (delegate != null) {
			delegate.deliverMessage(builder.toString());
		}

	}
}
